package com.hdaccp.dao.impl;

import com.hdaccp.dao.CommonDao;
import com.hdaccp.dao.StatusDao;
import com.hdaccp.entity.Status;
import com.hdaccp.util.BaseDao;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class StatusDaoimpl extends BaseDao implements CommonDao,StatusDao {
    @Override
    public List getAll() {
        return null;
    }

    @Override
    public Object getById(Serializable id) {
        return null;
    }

    @Override
    public boolean add(Object entity) {
        return false;
    }

    @Override
    public boolean update(Object entity) {
        return false;
    }

    @Override
    public boolean deleteById(Serializable id) {
        return false;
    }

	@Override
	public List<Status> getYS(int cid) {
		// TODO Auto-generated method stub
		String sql="select * from `status` where cid=?";
		Object [] params={cid};
		ResultSet rs=super.executeQuery(sql, params);
		List<Status> list=new ArrayList<Status>();
		try {
			while(rs.next()){
				Status s=new Status();
				s.setId(rs.getInt(1));
				s.setTime(rs.getDate(2).toString());
				s.setMaterials(rs.getFloat(3));
				s.setMate(rs.getFloat(4));
				s.setFee(rs.getFloat(5));
				s.setOther(rs.getFloat(6));
				s.setCid(rs.getInt(7));
				list.add(s);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				super.closeAll(rs, rs.getStatement(), rs.getStatement().getConnection());
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return list;
	}

	@Override
	public boolean updYD(Status s) {
		// TODO Auto-generated method stub
		String sql="update `status` set materials=?,mate=?,fee=?,other=? where id=? ";
		Object [] params={s.getMaterials(),s.getMate(),s.getFee(),s.getOther(),s.getId()};
		return super.executeUpdate(sql, params);
	}

	@Override
	public boolean insYS(Status s) {
		// TODO Auto-generated method stub
		String sql="insert into `status` values(null,NOW(),?,?,?,?,?)";
		Object [] params={s.getMaterials(),s.getMate(),s.getFee(),s.getOther(),s.getCid()};
		return super.executeUpdate(sql, params);
	}

	public Status getYID() {
		String sql="select * from `status` order by id desc limit 0,1";
		Object [] params=null;
		ResultSet rs=super.executeQuery(sql, params);
		Status s=null;
		try {
			while(rs.next()){
				s=new Status();
				s.setId(rs.getInt(1));
				s.setTime(rs.getDate(2).toString());
				s.setMaterials(rs.getFloat(3));
				s.setMate(rs.getFloat(4));
				s.setFee(rs.getFloat(5));
				s.setOther(rs.getFloat(6));
				s.setCid(rs.getInt(7));
				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				super.closeAll(rs, rs.getStatement(), rs.getStatement().getConnection());
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return s;
	}

	@Override
	public boolean delY(int id) {
		// TODO Auto-generated method stub
		String sql="delete from `status` where id=?";
		Object [] params={id};
		return super.executeUpdate(sql, params);
	}
}
